﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Leikjavefurinn.Repo
{
    public class ScoreboardRepo 
    {

        private GameDBDataContext _db = new GameDBDataContext();

        public Scoreboard GetScoreBoard(string userName)
        {
            var result = (from ux in _db.Scoreboards
                          join u in _db.Users on
                          ux.User equals u.UserId
                          where u.UserName == userName
                          select ux).SingleOrDefault();

            return result;
        }

        public void CreateScoreBoard(string userName)
        {
            var user = _db.Users.SingleOrDefault(n => n.UserName == userName);

            _db.Scoreboards.InsertOnSubmit(new Scoreboard { User = user.UserId });
            _db.SubmitChanges();
        }

        public void Save()
        {
            _db.SubmitChanges();
        }

 
    }
}
